package edu.mju.eduStatistics.controller;


import edu.mju.commonutils.ReturnCode;
import edu.mju.eduStatistics.service.StatisticsDailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author xiaoxin
 * @since 2020-11-13
 */
@RestController
@RequestMapping("/eduStatistics/statistics-daily")
public class StatisticsDailyController {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    /**
     * 统计某一天的注册人数 并向数据库加入数据
     * @param day
     * @return
     */
    @PostMapping("/registerCount/{day}")
    public ReturnCode registerCount(@PathVariable String day){
        statisticsDailyService.registerCount(day);
        return ReturnCode.success();
    }

    /**
     *  图表显示统计数据
     * @param type 类型
     * @param begin 开始日期
     * @param end 结束日期
     * @return 返回日期json数据，数量json数据
     */
    @GetMapping("/showData/{type}/{begin}/{end}")
    public ReturnCode showData(@PathVariable String type,@PathVariable String begin,@PathVariable String end){

        Map<String,Object> map = statisticsDailyService.getShowData(type,begin,end);

        return ReturnCode.success().data(map);
    }
}

